import gtk

class Rule_menu:
    def on_change_button(self, widget, data):
        win = data
        if win.pos == 0:
            win.width          = gtk.gdk.screen_width()/20
            win.height         = gtk.gdk.screen_height()#2/3
            win.pos            = 1
            win.win.resize(win.width, win.height)
            win.draw.set_size_request(win.width, win.height)
        else:
            win.width          = gtk.gdk.screen_width()#/2
            win.height         = gtk.gdk.screen_height()/15
            win.pos            = 0
            win.win.resize(win.width, win.height)
            win.draw.set_size_request(win.width, win.height)

    def on_unit_button_cm(self, widget, data):
        data.rule_type = 0
        data.bg_color   = gtk.gdk.Color(231*257, 227*257, 107*257)
        data.draw_expose_event(data.win, gtk.gdk.event_get())

    def on_unit_button_px(self, widget, data):
        data.rule_type = 1
        data.bg_color   = gtk.gdk.Color(222*257, 146*257, 148*257)
        data.draw_expose_event(data.win, gtk.gdk.event_get())

    def on_unit_button_in(self, widget, data):
        data.rule_type = 2
        data.bg_color   = gtk.gdk.Color(156*257, 227*257, 107*257)
        data.draw_expose_event(data.win, gtk.gdk.event_get())

    def on_unit_button_pt(self, widget, data):
        data.rule_type = 3
        data.bg_color   = gtk.gdk.Color(156*257, 146*257, 99*257)
        data.draw_expose_event(data.win, gtk.gdk.event_get())

    def on_unit_button_pc(self, widget, data):
        data.rule_type = 4
        data.bg_color   = gtk.gdk.Color(156*257, 170*257, 222*257)
        data.draw_expose_event(data.win, gtk.gdk.event_get())

    def on_quit_button(self, widget, data):
        exit()

    def __init__(self, widget):
        self.menu       = gtk.Menu()
        change_button   = gtk.MenuItem("Position change")
        unit_button_cm  = gtk.MenuItem("Centimetre")
        unit_button_px  = gtk.MenuItem("Pixel")
        unit_button_in  = gtk.MenuItem("Inch")
        unit_button_pt  = gtk.MenuItem("Point")
        unit_button_pc  = gtk.MenuItem("Pica")
        quit_button     = gtk.MenuItem("Quit")
        for i in [change_button, gtk.SeparatorMenuItem(),
                    unit_button_cm,
                    unit_button_px,
                    unit_button_in,
                    unit_button_pt,
                    unit_button_pc, gtk.SeparatorMenuItem(),
                    quit_button]:
            self.menu.append(i)
        self.menu.show_all()

        change_button.connect("activate", self.on_change_button, widget)
        unit_button_cm.connect("activate", self.on_unit_button_cm, widget)
        unit_button_px.connect("activate", self.on_unit_button_px, widget)
        unit_button_in.connect("activate", self.on_unit_button_in, widget)
        unit_button_pt.connect("activate", self.on_unit_button_pt, widget)
        unit_button_pc.connect("activate", self.on_unit_button_pc, widget)
        quit_button.connect("activate", self.on_quit_button, widget)